﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Media.Imaging;

namespace MyBet.Class
{
    public class ImageUtil
    {
        public static BitmapImage byteArrayToImage(byte[] byteArrayIn)
        {
            BitmapImage _img = new BitmapImage();
            try
            {
                Stream _s = new MemoryStream(byteArrayIn);
                _s.Position = 0;
                _img.SetSource(_s);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            return _img;
        }

        public static Color HexColor(String hex)
        { 
            //remove the # at the front 
            hex = hex.Replace("#", ""); 
            byte a = 255; 
            byte r = 255; 
            byte g = 255; 
            byte b = 255; 
            int start = 0; 
            //handle ARGB strings (8 characters long) 
            if (hex.Length == 8) 
            {     
                a = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);     
                start = 2; 
            } 
            //convert RGB characters to bytes 
            r = byte.Parse(hex.Substring(start, 2), System.Globalization.NumberStyles.HexNumber); 
            g = byte.Parse(hex.Substring(start+2, 2), System.Globalization.NumberStyles.HexNumber); 
            b = byte.Parse(hex.Substring(start+4, 2), System.Globalization.NumberStyles.HexNumber); 
            return Color.FromArgb(a, r, g, b);
        }

    }
}
